/*
 * PEGPlot.java
 * Created on September 8, 2007, 8:59 AM
 */

    package applications;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.event.InternalFrameEvent;
import javax.xml.bind.JAXBException;
import sequor.editor.ComboBoxEditor;
import java.io.File;
import javax.swing.JFileChooser;
import javax.swing.UIManager;
import javax.swing.filechooser.FileFilter;
import metrics.Valuation;
import sequor.SettingsFactory;
import sequor.style.AnimateLineStyle;
import simulation.Simulation;
import simulation.Team;
import utility.SimulationFactory;
import utility.XmlHandler;

/**
 *
 * @author  ae3263
 */
public class PEGPlot extends javax.swing.JFrame {
    
    final JFileChooser fc = new JFileChooser();    /*
     * Get the extension of a file.
     */  
    public static String getExtension(File f) {
        String ext = null;
        String s = f.getName();
        int i = s.lastIndexOf('.');

        if (i > 0 &&  i < s.length() - 1) {
            ext = s.substring(i+1).toLowerCase();
        }
        return ext;
    }

    
    /** Creates new form PEGPlot */
    @SuppressWarnings("unchecked")
    public PEGPlot() {    
        try { UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName()); } catch (Exception e) {}

        initComponents();
        
        fc.addChoosableFileFilter(new FileFilter(){
            public boolean accept(File f) {
                return (f.isDirectory())
                        || getExtension(f).equals("xml");
            }
            @Override
            public String getDescription() { return "XML Simulation File (.xml)"; }
        });
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        simPanel1 = new applications.SimPanel();
        numBatchRunsModel = new sequor.model.IntegerRangeModel(100,0,100000);
        animationStyleGroup = new javax.swing.ButtonGroup();
        simulation1 = new simulation.Simulation();
        statusBar = new javax.swing.JPanel();
        statusText = new javax.swing.JLabel();
        jToolBar1 = new javax.swing.JToolBar();
        jLabel1 = new javax.swing.JLabel();
        simulationComboBox = new javax.swing.JComboBox();
        jSeparator1 = new javax.swing.JToolBar.Separator();
        randomizeButton = new javax.swing.JButton();
        batchButton = new javax.swing.JButton();
        numBatchRunsSpinner = SettingsFactory.getSpinner(numBatchRunsModel);
        cooperationButton = new javax.swing.JButton();
        jDesktopPane1 = new javax.swing.JDesktopPane();
        jMenuBar1 = new javax.swing.JMenuBar();
        fileMenu = new javax.swing.JMenu();
        newMenuItem = new javax.swing.JMenuItem();
        openMenuItem = new javax.swing.JMenuItem();
        saveMenuItem = new javax.swing.JMenuItem();
        quitMenuItem = new javax.swing.JMenuItem();
        simulationMenu = new javax.swing.JMenu();
        randomizeMenuItem = new javax.swing.JMenuItem();
        animateMenuItem = new javax.swing.JMenuItem();
        duplicateMenuItem = new javax.swing.JMenuItem();
        appearanceMenu = new javax.swing.JMenu();
        showAnimationControlsMI = new javax.swing.JCheckBoxMenuItem();
        showMarkerBoxMI = new javax.swing.JCheckBoxMenuItem();
        show3DControlsMI = new javax.swing.JCheckBoxMenuItem();
        animationMenu = new javax.swing.JMenu();
        showStartingMI = new javax.swing.JCheckBoxMenuItem();
        showPositionLabelsMI = new javax.swing.JCheckBoxMenuItem();
        showCommMI = new javax.swing.JCheckBoxMenuItem();
        jSeparator4 = new javax.swing.JSeparator();
        animateDrawPathsMI = new javax.swing.JRadioButtonMenuItem();
        animateTracePathsMI = new javax.swing.JRadioButtonMenuItem();
        animateMovingDotsMI = new javax.swing.JRadioButtonMenuItem();
        animateMovingTrianglesMI = new javax.swing.JRadioButtonMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Pursuit-Evasion Games");

        statusBar.setBackground(new java.awt.Color(255, 255, 255));
        statusBar.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        statusText.setText("Awaiting user instructions.");

        javax.swing.GroupLayout statusBarLayout = new javax.swing.GroupLayout(statusBar);
        statusBar.setLayout(statusBarLayout);
        statusBarLayout.setHorizontalGroup(
            statusBarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(statusText, javax.swing.GroupLayout.DEFAULT_SIZE, 1042, Short.MAX_VALUE)
        );
        statusBarLayout.setVerticalGroup(
            statusBarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(statusText)
        );

        getContentPane().add(statusBar, java.awt.BorderLayout.SOUTH);

        jToolBar1.setRollover(true);

        jLabel1.setText("Game Preset:  ");
        jToolBar1.add(jLabel1);

        simulationComboBox.setModel(new ComboBoxEditor(SimulationFactory.comboBoxRangeModel()));
        simulationComboBox.setMaximumSize(new java.awt.Dimension(250, 20));
        simulationComboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                simulationComboBoxActionPerformed(evt);
            }
        });
        jToolBar1.add(simulationComboBox);
        jToolBar1.add(jSeparator1);

        randomizeButton.setFont(new java.awt.Font("Tahoma", 1, 12));
        randomizeButton.setText("RANDOMIZE");
        randomizeButton.setToolTipText("Click here to reset the simulation and re-randomize starting positions.");
        randomizeButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                randomizeButtonActionPerformed(evt);
            }
        });
        jToolBar1.add(randomizeButton);

        batchButton.setFont(new java.awt.Font("Tahoma", 1, 12));
        batchButton.setText("BATCH");
        batchButton.setFocusable(false);
        batchButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        batchButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        batchButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                batchButtonActionPerformed(evt);
            }
        });
        jToolBar1.add(batchButton);

        numBatchRunsSpinner.setMaximumSize(new java.awt.Dimension(70, 32767));
        jToolBar1.add(numBatchRunsSpinner);

        cooperationButton.setFont(new java.awt.Font("Tahoma", 1, 12));
        cooperationButton.setText("COOPERATION");
        cooperationButton.setFocusable(false);
        cooperationButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        cooperationButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        cooperationButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cooperationButtonActionPerformed(evt);
            }
        });
        jToolBar1.add(cooperationButton);

        getContentPane().add(jToolBar1, java.awt.BorderLayout.NORTH);

        jDesktopPane1.setPreferredSize(new java.awt.Dimension(600, 500));
        getContentPane().add(jDesktopPane1, java.awt.BorderLayout.CENTER);

        fileMenu.setText("File");

        newMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_N, java.awt.event.InputEvent.CTRL_MASK));
        newMenuItem.setText("New Simulation");
        newMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                newMenuItemActionPerformed(evt);
            }
        });
        fileMenu.add(newMenuItem);

        openMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_O, java.awt.event.InputEvent.CTRL_MASK));
        openMenuItem.setText("Open Simulation");
        openMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                openMenuItemActionPerformed(evt);
            }
        });
        fileMenu.add(openMenuItem);

        saveMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.CTRL_MASK));
        saveMenuItem.setText("Save Simulation");
        saveMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saveMenuItemActionPerformed(evt);
            }
        });
        fileMenu.add(saveMenuItem);

        quitMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_Q, java.awt.event.InputEvent.CTRL_MASK));
        quitMenuItem.setText("Quit");
        quitMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                quitMenuItemActionPerformed(evt);
            }
        });
        fileMenu.add(quitMenuItem);

        jMenuBar1.add(fileMenu);

        simulationMenu.setText("Simulation");

        randomizeMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_R, java.awt.event.InputEvent.CTRL_MASK));
        randomizeMenuItem.setText("Randomize Starting Locations");
        randomizeMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                randomizeButtonActionPerformed(evt);
            }
        });
        simulationMenu.add(randomizeMenuItem);

        animateMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_A, java.awt.event.InputEvent.ALT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        animateMenuItem.setText("Animate Simulation");
        animateMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                animateMenuItemActionPerformed(evt);
            }
        });
        simulationMenu.add(animateMenuItem);

        duplicateMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_D, java.awt.event.InputEvent.CTRL_MASK));
        duplicateMenuItem.setText("Duplicate Simulation");
        duplicateMenuItem.setEnabled(false);
        duplicateMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                duplicateMenuItemActionPerformed(evt);
            }
        });
        simulationMenu.add(duplicateMenuItem);

        jMenuBar1.add(simulationMenu);

        appearanceMenu.setText("Window Appearance");

        showAnimationControlsMI.setSelected(true);
        showAnimationControlsMI.setText("Show animation controls");
        showAnimationControlsMI.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                showAnimationControlsMIActionPerformed(evt);
            }
        });
        appearanceMenu.add(showAnimationControlsMI);

        showMarkerBoxMI.setText("Show marker box");
        showMarkerBoxMI.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                showMarkerBoxMIActionPerformed(evt);
            }
        });
        appearanceMenu.add(showMarkerBoxMI);

        show3DControlsMI.setText("Show 3d controls");
        show3DControlsMI.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                show3DControlsMIActionPerformed(evt);
            }
        });
        appearanceMenu.add(show3DControlsMI);

        jMenuBar1.add(appearanceMenu);

        animationMenu.setText("Path Appearance");

        showStartingMI.setSelected(true);
        showStartingMI.setText("Show starting points");
        showStartingMI.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                showStartingMIActionPerformed(evt);
            }
        });
        animationMenu.add(showStartingMI);

        showPositionLabelsMI.setSelected(true);
        showPositionLabelsMI.setText("Show position labels");
        showPositionLabelsMI.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                showPositionLabelsMIActionPerformed(evt);
            }
        });
        animationMenu.add(showPositionLabelsMI);

        showCommMI.setText("Show comm networks");
        showCommMI.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                showCommMIActionPerformed(evt);
            }
        });
        animationMenu.add(showCommMI);
        animationMenu.add(jSeparator4);

        animationStyleGroup.add(animateDrawPathsMI);
        animateDrawPathsMI.setSelected(true);
        animateDrawPathsMI.setText("Draw paths");
        animateDrawPathsMI.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                animateDrawPathsMIActionPerformed(evt);
            }
        });
        animationMenu.add(animateDrawPathsMI);

        animationStyleGroup.add(animateTracePathsMI);
        animateTracePathsMI.setText("Trace paths");
        animateTracePathsMI.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                animateTracePathsMIActionPerformed(evt);
            }
        });
        animationMenu.add(animateTracePathsMI);

        animationStyleGroup.add(animateMovingDotsMI);
        animateMovingDotsMI.setText("Moving dots");
        animateMovingDotsMI.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                animateMovingDotsMIActionPerformed(evt);
            }
        });
        animationMenu.add(animateMovingDotsMI);

        animationStyleGroup.add(animateMovingTrianglesMI);
        animateMovingTrianglesMI.setText("Moving triangles");
        animateMovingTrianglesMI.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                animateMovingTrianglesMIActionPerformed(evt);
            }
        });
        animationMenu.add(animateMovingTrianglesMI);

        jMenuBar1.add(animationMenu);

        setJMenuBar(jMenuBar1);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void batchButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_batchButtonActionPerformed
        statusText.setText("Batching "+numBatchRunsModel.getValue()+" runs... this may take a while!");
        simulation1.runSeveral(numBatchRunsModel.getValue());
}//GEN-LAST:event_batchButtonActionPerformed

private void quitMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_quitMenuItemActionPerformed
    statusText.setText("Goodbye!");
    System.exit(0);
}//GEN-LAST:event_quitMenuItemActionPerformed

private void randomizeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_randomizeButtonActionPerformed
    statusText.setText("Randomizing starting locations...");
    simPanel1.log("\nNEW SIMULATION");
    simulation1.initStartingLocations();
    simulation1.run();
    success();
}//GEN-LAST:event_randomizeButtonActionPerformed

private void success(){
    statusText.setText("Success! Awaiting further instructions.");
}

    private void cooperationButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cooperationButtonActionPerformed
        statusText.setText("Printing cooperation metrics...");
        for (Team t : simulation1.getTeams()) {
            if (t.victory != null) {
                simPanel1.log(t.victory.getCooperationMetric(simulation1).toString());
            }
            for (Valuation v : t.metrics) {
                simPanel1.log(v.getCooperationMetric(simulation1).toString());
            }
        }    
        statusText.setText("Success! Check the log window for cooperation metrics.");
}//GEN-LAST:event_cooperationButtonActionPerformed

private void animateMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_animateMenuItemActionPerformed
    simPanel1.animate();
}//GEN-LAST:event_animateMenuItemActionPerformed

private void openMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_openMenuItemActionPerformed
    int returnVal = fc.showOpenDialog(this);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
            try {
                File file = fc.getSelectedFile();
                //This is where a real application would open the file.
                statusText.setText("Opening: " + file.getName() + ".");
                addFrame(XmlHandler.unmarshal(file));
            } catch (JAXBException ex) {
                Logger.getLogger(PEGPlot.class.getName()).log(Level.SEVERE, null, ex);
            } catch (FileNotFoundException ex) {
                Logger.getLogger(PEGPlot.class.getName()).log(Level.SEVERE, null, ex);
            } catch (IOException ex) {
                Logger.getLogger(PEGPlot.class.getName()).log(Level.SEVERE, null, ex);
            } 
    } else {
        statusText.setText("Open command cancelled by user.");
    }
}//GEN-LAST:event_openMenuItemActionPerformed

private void saveMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveMenuItemActionPerformed
    int returnVal = fc.showSaveDialog(this);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
            try {
                File file = fc.getSelectedFile();
                //This is where a real application would open the file.
                statusText.setText("Saving: " + file.getName() + ".");
                XmlHandler.marshal(simulation1, file);
            } catch (FileNotFoundException ex) {
                Logger.getLogger(PEGPlot.class.getName()).log(Level.SEVERE, null, ex);
            } catch (JAXBException ex) {
                Logger.getLogger(PEGPlot.class.getName()).log(Level.SEVERE, null, ex);
            } catch (IOException ex) {
                Logger.getLogger(PEGPlot.class.getName()).log(Level.SEVERE, null, ex);
            } 
    } else {
        statusText.setText("Save command cancelled by user.");
    }
}//GEN-LAST:event_saveMenuItemActionPerformed

private void showAnimationControlsMIActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_showAnimationControlsMIActionPerformed
    simPanel1.setAnimatorVisible(showAnimationControlsMI.getState());
}//GEN-LAST:event_showAnimationControlsMIActionPerformed

private void showMarkerBoxMIActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_showMarkerBoxMIActionPerformed
    simPanel1.setMarkerBoxVisible(showMarkerBoxMI.getState());
}//GEN-LAST:event_showMarkerBoxMIActionPerformed

private void show3DControlsMIActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_show3DControlsMIActionPerformed
    simPanel1.set3DItemsVisible(show3DControlsMI.getState());
}//GEN-LAST:event_show3DControlsMIActionPerformed

private void animateDrawPathsMIActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_animateDrawPathsMIActionPerformed
    simPanel1.setAnimationStyle(AnimateLineStyle.ANIMATE_TRAIL);
}//GEN-LAST:event_animateDrawPathsMIActionPerformed

private void animateMovingDotsMIActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_animateMovingDotsMIActionPerformed
    simPanel1.setAnimationStyle(AnimateLineStyle.ANIMATE_DOT);
}//GEN-LAST:event_animateMovingDotsMIActionPerformed

private void animateTracePathsMIActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_animateTracePathsMIActionPerformed
    simPanel1.setAnimationStyle(AnimateLineStyle.ANIMATE_TRACE);
}//GEN-LAST:event_animateTracePathsMIActionPerformed

private void showCommMIActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_showCommMIActionPerformed
    simPanel1.setNetworkVisible(showCommMI.getState());
}//GEN-LAST:event_showCommMIActionPerformed

private void showPositionLabelsMIActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_showPositionLabelsMIActionPerformed
    simPanel1.setPositionsVisible(showPositionLabelsMI.getState());
}//GEN-LAST:event_showPositionLabelsMIActionPerformed

private void showStartingMIActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_showStartingMIActionPerformed
    simPanel1.setStartVisible(showStartingMI.getState());
}//GEN-LAST:event_showStartingMIActionPerformed

private void duplicateMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_duplicateMenuItemActionPerformed
    SimInternalFrame s2 = new SimInternalFrame("Copy");
    s2.simPanel1.setSimulation(simulation1.copy());
    s2.setBounds(20, 10, 802, 493);
    jDesktopPane1.add(s2, javax.swing.JLayeredPane.DEFAULT_LAYER);
}//GEN-LAST:event_duplicateMenuItemActionPerformed

private void simulationComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_simulationComboBoxActionPerformed
    addFrame(new simulation.Simulation(simulationComboBox.getSelectedIndex()));
}//GEN-LAST:event_simulationComboBoxActionPerformed

private void animateMovingTrianglesMIActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_animateMovingTrianglesMIActionPerformed
    simPanel1.setAnimationStyle(AnimateLineStyle.ANIMATE_VEC);
}//GEN-LAST:event_animateMovingTrianglesMIActionPerformed

private void newMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newMenuItemActionPerformed
    addFrame(new Simulation());
}//GEN-LAST:event_newMenuItemActionPerformed
    
    /**
     * @param args the command lineSegment arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new PEGPlot().setVisible(true);
            }
        });
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JRadioButtonMenuItem animateDrawPathsMI;
    private javax.swing.JMenuItem animateMenuItem;
    private javax.swing.JRadioButtonMenuItem animateMovingDotsMI;
    private javax.swing.JRadioButtonMenuItem animateMovingTrianglesMI;
    private javax.swing.JRadioButtonMenuItem animateTracePathsMI;
    private javax.swing.JMenu animationMenu;
    private javax.swing.ButtonGroup animationStyleGroup;
    private javax.swing.JMenu appearanceMenu;
    private javax.swing.JButton batchButton;
    private javax.swing.JButton cooperationButton;
    private javax.swing.JMenuItem duplicateMenuItem;
    private javax.swing.JMenu fileMenu;
    private javax.swing.JDesktopPane jDesktopPane1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JToolBar.Separator jSeparator1;
    private javax.swing.JSeparator jSeparator4;
    private javax.swing.JToolBar jToolBar1;
    private javax.swing.JMenuItem newMenuItem;
    private sequor.model.IntegerRangeModel numBatchRunsModel;
    private javax.swing.JSpinner numBatchRunsSpinner;
    private javax.swing.JMenuItem openMenuItem;
    private javax.swing.JMenuItem quitMenuItem;
    private javax.swing.JButton randomizeButton;
    private javax.swing.JMenuItem randomizeMenuItem;
    private javax.swing.JMenuItem saveMenuItem;
    private javax.swing.JCheckBoxMenuItem show3DControlsMI;
    private javax.swing.JCheckBoxMenuItem showAnimationControlsMI;
    private javax.swing.JCheckBoxMenuItem showCommMI;
    private javax.swing.JCheckBoxMenuItem showMarkerBoxMI;
    private javax.swing.JCheckBoxMenuItem showPositionLabelsMI;
    private javax.swing.JCheckBoxMenuItem showStartingMI;
    private applications.SimPanel simPanel1;
    private simulation.Simulation simulation1;
    private javax.swing.JComboBox simulationComboBox;
    private javax.swing.JMenu simulationMenu;
    private javax.swing.JPanel statusBar;
    private javax.swing.JLabel statusText;
    // End of variables declaration//GEN-END:variables


    private void addFrame(Simulation sim) {
        SimInternalFrame sNew = new SimInternalFrame(sim.getName());
        sNew.simPanel1.setSimulation(sim);        
        jDesktopPane1.add(sNew);
        sNew.addInternalFrameListener(new MyFrameListener());
        simulation1.update();
        jDesktopPane1.setSelectedFrame(sNew);
    }

    private class MyFrameListener extends javax.swing.event.InternalFrameAdapter {
        @Override
        public void internalFrameActivated(InternalFrameEvent e) {
            simulation1 = ((SimInternalFrame)(e.getInternalFrame())).simPanel1.getSimulation();
            simPanel1 = ((SimInternalFrame)(e.getInternalFrame())).simPanel1;
            
            simPanel1.set3DItemsVisible(show3DControlsMI.getState());
            simPanel1.setAnimatorVisible(showAnimationControlsMI.getState());
            simPanel1.setNetworkVisible(showCommMI.getState());
            simPanel1.setMarkerBoxVisible(showMarkerBoxMI.getState());
            simPanel1.setPositionsVisible(showPositionLabelsMI.getState());
            simPanel1.setStartVisible(showStartingMI.getState());

            if (animateDrawPathsMI.isSelected()) {
                simPanel1.setAnimationStyle(AnimateLineStyle.ANIMATE_TRAIL);
            } else if (animateTracePathsMI.isSelected()) {
                simPanel1.setAnimationStyle(AnimateLineStyle.ANIMATE_TRACE);
            } else if (animateMovingDotsMI.isSelected()) {
                simPanel1.setAnimationStyle(AnimateLineStyle.ANIMATE_DOT);
            } else if (animateMovingTrianglesMI.isSelected()) {
                simPanel1.setAnimationStyle(AnimateLineStyle.ANIMATE_VEC);
            }
        }
    }
}
